package cn.lysj.framework.elm.controller;

import cn.lysj.framework.base.BaseController;
import cn.lysj.framework.common.annotation.CurrentUser;
import cn.lysj.framework.common.domain.User;
import cn.lysj.framework.common.utils.web.ParamUtil;
import cn.lysj.framework.common.utils.web.Resp;
import cn.lysj.framework.elm.domain.FoodReleveEleme;
import cn.lysj.framework.elm.service.FoodRelevElemeService;
import cn.lysj.framework.foodv2.service.FoodService;
import eleme.openapi.sdk.api.exception.ServiceException;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @ Author ：drj.
 * @ Date  ：Created in 15:11 2019/1/16
 * @ Description:
 **/
@Slf4j
@RestController
@Api(description = "本地菜品跟饿了么关联")
@RequestMapping("/food_relev_eleme")
public class FoodRelevElemeController extends BaseController<FoodReleveEleme> {


    @Resource
    private FoodRelevElemeService foodRelevElemeService;

    @Override
    public FoodRelevElemeService getService() {
        return foodRelevElemeService;
    }


    /**
     * @author drj
     * @date 2019/1/17 15:12
     * @Description :获取与饿了么未关联的平台菜品
     */
    @GetMapping("/get_un_releve_plat_form_food")
    public Resp getUnRelevePlatFormFood(@CurrentUser User user) {
        return new Resp(foodRelevElemeService.getUnRevElmPlatFood(user));
    }


    //获取未关联饿了么菜品
    @GetMapping("/get_un_releve_eleme_food")
    public Resp getUnReleveElemeFood(@CurrentUser User user) {
        return new Resp(foodRelevElemeService.getUnReleveElemeFood(user));
    }


    /**
     * @author drj
     * @date 2019/1/17 15:37
     * @Description:获取关联菜品信息
     */
    @GetMapping("/relev_eleme_info")
    public Resp relevElemeInfo(@CurrentUser User user) {
        return new Resp(foodRelevElemeService.relevElemeInfo(user));
    }

    //取消关联
    @PostMapping("/cancle_releve")
    public Resp cancleReleve(String foodRelevElemeId) {
        if (ParamUtil.isBlank(foodRelevElemeId)) {
            return new Resp(Resp.PARAM_ERROR, "参数错误");
        }
        foodRelevElemeService.delete(foodRelevElemeId);
        return new Resp("操作成功");
    }

    //选择关联
    @PostMapping("/choose_releve")
    public Resp chooseReleve(String platFormFoodId, String elemeFoodId, @CurrentUser User user) {
        if (ParamUtil.isBlank(platFormFoodId)) {
            return new Resp(Resp.PARAM_ERROR, "请选择平台菜品");
        }
        if (ParamUtil.isBlank(elemeFoodId)) {
            return new Resp(Resp.PARAM_ERROR, "请选择饿了么菜品");
        }
        FoodReleveEleme foodReleveEleme = new FoodReleveEleme();
        foodReleveEleme.setStoreId(user.getStoreId());
        foodReleveEleme.setPlatFormFoodId(platFormFoodId);
        foodReleveEleme.setElemeFoodId(elemeFoodId);
        foodRelevElemeService.save(foodReleveEleme);
        return new Resp("操作成功");
    }


}
